<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core">

<ui:composition template="/common/template.xhtml">

	<ui:define name="headSection">

	</ui:define>

	<ui:define name="pageContent">

		<h:form>
			<h:panelGroup>
				<table class="mainTable" style="margin-bottom: 10px;">
					<tr>
						<td><h:outputLabel value="Регистрационен номер">
								<br />
								<h:inputText value="#{aktualiziraneNaDiagnostika.searchPlateNumber}" maxlength="8" />
							</h:outputLabel></td>
						<td><h:outputLabel value="Начална дата">
								<br />
								<h:inputText value="#{aktualiziraneNaDiagnostika.searchDateFrom}" title="ДД.ММ.ГГГГ"
									convertorMessage="Невалидна дата. Пример: 21.12.2012">
									<f:convertDateTime pattern="dd.MM.yyyy" />
								</h:inputText>
							</h:outputLabel></td>
						<td><h:outputLabel value="Крайна дата">
								<br />
								<h:inputText value="#{aktualiziraneNaDiagnostika.searchDateTo}" title="ДД.ММ.ГГГГ"
									convertorMessage="Невалидна дата. Пример: 21.12.2012">
									<f:convertDateTime pattern="dd.MM.yyyy" />
								</h:inputText>
							</h:outputLabel></td>
					</tr>
					<tr>
						<td colspan="2">
							<h:commandButton value="Търси" class="regButton"
								style="width:80px;height:40px;margin-left:20px;"
								action="#{aktualiziraneNaDiagnostika.searchIt()}" />
							<h:commandButton value="Изчисти" class="regButton"
								style="width:80px;height:40px;"
								action="#{aktualiziraneNaDiagnostika.resetSearch()}" />
						</td>
					</tr>
				</table>
			</h:panelGroup>
		</h:form>

		<div id="scroolTable">
			<!-- scroll bar -->
			<h:form>

				<!-- за Калин - избрания ред ще има клас = "selectedRow", неизбраните = "notSelectedRow" -->
				<h:dataTable rows="#{configurationProperties.getPageSize()}"
					value="#{aktualiziraneNaDiagnostika.spisukDiagnostiki}" first="0"
					var="curr"
					rowClasses="#{aktualiziraneNaDiagnostika.rowStyleClasses}">

					<h:column>
						<f:facet name="header">Номер на рама</f:facet>
						<h:outputText value="#{curr.vehicle.VIN}" />
					</h:column>

					<h:column>
						<f:facet name="header">Регистрационен номер</f:facet>
						<h:outputText value="#{curr.vehicle.plateNumber}" />
					</h:column>

					<h:column>
						<f:facet name="header">Дата</f:facet>
						<h:outputText value="#{curr.date}">
							<f:convertDateTime pattern="dd.MM.yyyy" />
						</h:outputText>
					</h:column>

					<h:column>
						<f:facet name="header">Цена</f:facet>
						<h:outputText value="#{curr.price}" />
					</h:column>

					<h:column>
						<f:facet name="header">Промени</f:facet>
						<h:commandButton
							action="#{aktualiziraneNaDiagnostika.selectRow(curr)}"
							value="Промени" class="inTableButton"/>
					</h:column>

					<h:column rendered="#{aktualiziraneNaDiagnostika.choosingAllowed}">
						<f:facet name="header">Избери</f:facet>
						<h:commandButton
							action="#{aktualiziraneNaDiagnostika.chooseDiagnostika(curr)}"
							value="Избери" class="inTableButton"/>
					</h:column>

					<f:facet name="footer">

						<!-- предишна страница -->
						<h:commandLink
							disabled="#{aktualiziraneNaDiagnostika.page - 1 lt 0}"
							action="#{aktualiziraneNaDiagnostika.setPage(aktualiziraneNaDiagnostika.page - 1)}"
							value="&lt;&lt;" />

						<h:outputText value=" " />

						<!-- други страници -->
						<ui:repeat value="#{aktualiziraneNaDiagnostika.pagesList}"
							var="currPage">
							<h:commandLink
								disabled="#{aktualiziraneNaDiagnostika.getPage() eq currPage.intValue() - 1}"
								action="#{aktualiziraneNaDiagnostika.setPage(currPage.intValue() - 1)}"
								value="#{currPage}" />

							<h:outputText value=" " />
						</ui:repeat>

						<!-- следваща страница -->
						<h:commandLink
							disabled="#{aktualiziraneNaDiagnostika.page + 1 ge aktualiziraneNaDiagnostika.pagesCount}"
							action="#{aktualiziraneNaDiagnostika.setPage(aktualiziraneNaDiagnostika.page + 1)}"
							value="&gt;&gt;" />

					</f:facet>

				</h:dataTable>

			</h:form>
		</div>

		<h:form>
			<table class="mainTable">
				<tr>
					<td><h:outputLabel value="Номер на рама*">
							<br />
							<h:inputText id="vin"
								value="#{aktualiziraneNaDiagnostika.vehicle.VIN}" maxlength="17"
								readonly="true" />
						</h:outputLabel></td>
					<td><h:outputLabel value="Автосервиз*">
							<br />
							<h:inputText id="avtoserviz"
								value="#{aktualiziraneNaDiagnostika.autoservice.name}"
								maxlength="100" readonly="true" />
						</h:outputLabel></td>
					<td><h:outputLabel value="Дата на извършената диагностиката*">
							<br />
							<h:inputText id="date" value="#{aktualiziraneNaDiagnostika.date}"
								readonly="true">
								<f:convertDateTime pattern="dd.MM.yyyy" />
							</h:inputText>
						</h:outputLabel></td>
				</tr>
				<tr>
					<td colspan="2" style="text-align: center;"><h:outputLabel
							value="Служител направил диагностиката*">
							<br />
							<h:inputText id="empname"
								value="#{aktualiziraneNaDiagnostika.employee.name}"
								maxlength="50" readonly="true" />
							<h:inputText id="empfamily"
								value="#{aktualiziraneNaDiagnostika.employee.family}"
								maxlength="50" readonly="true" />
						</h:outputLabel></td>
					<td><h:outputLabel value="Цена на диагностиката*">
							<br />
							<h:inputText id="price"
								value="#{aktualiziraneNaDiagnostika.price}" maxlength="10"
								readonly="true" />
						</h:outputLabel></td>
				</tr>
				<tr>
					<td><h:outputLabel value="Статус на диагностиката*">
							<br />
							<h:selectOneMenu value="#{aktualiziraneNaDiagnostika.status}"
								disabled="#{!aktualiziraneNaDiagnostika.rowSelected || aktualiziraneNaDiagnostika.isPaied()}">
								<f:selectItems value="#{aktualiziraneNaDiagnostika.diagStatus}" />
							</h:selectOneMenu>
						</h:outputLabel></td>

					<td><h:outputLabel value="Номер на платежно нареждане">
							<br />
							<h:inputText id="paynumber"
								value="#{aktualiziraneNaDiagnostika.paymentNumber}"
								maxlength="50"
								readonly="#{!aktualiziraneNaDiagnostika.rowSelected || aktualiziraneNaDiagnostika.isPaied()}" />

						</h:outputLabel></td>
				</tr>
			</table>


			<h:outputLabel
				value="Услуги, които трябва да бъдат извършени според извършената диагностика:"
				style="margin-left:150px;margin-bottom:10px;">
			</h:outputLabel>
			<br />
			<div style="overflow-x: auto;">
				<!-- scroll bar -->
				<h:dataTable value="#{aktualiziraneNaDiagnostika.spisukUslugi}"
					var="curr" rowClasses="notSelectedRow">

					<h:column>
						<f:facet name="header">Наименование на услугата</f:facet>
					#{curr.service.description}
				</h:column>

				</h:dataTable>
			</div>
			<br />

			<h:outputLabel
				value="Резервни части, които трябва да бъдат сменени според извършената диагностика:"
				style="margin-left:125px;margin-bottom:10px;">
			</h:outputLabel>
			<br />
			<div style="overflow-x: auto;">
				<!-- scroll bar -->
				<h:dataTable
					value="#{aktualiziraneNaDiagnostika.spisukRezervni4asti}"
					var="curr" rowClasses="notSelectedRow">

					<h:column>
						<f:facet name="header">Група на резервната част</f:facet>
					#{curr.sparePart.sparePartGroup.description}
				</h:column>

					<h:column>
						<f:facet name="header">Име на резервната част</f:facet>
					#{curr.sparePart.name}
				</h:column>

					<h:column>
						<f:facet name="header">Нужно количество</f:facet>
					#{curr.quantity}
				</h:column>

				</h:dataTable>
			</div>
			<br />

			<h:commandButton value="Запази" class="regButton"
				style="width:80px;height:40px;margin-top:20px;float:right;"
				action="#{aktualiziraneNaDiagnostika.saveDiagnostika()}"
				disabled="#{!aktualiziraneNaDiagnostika.rowSelected or !aktualiziraneNaDiagnostika.changingAllowed}" />

		</h:form>

		<h:form>
			<!-- формата е разделена на две, за да не се проверяват данните
		при натискането на бутоните "Отмени" и "Добави" -->

			<h:commandButton action="#{aktualiziraneNaDiagnostika.deselectRow()}"
				value="Отмени" class="regButton"
				style="width:80px;height:40px;float:right;margin-top:20px;"
				disabled="#{!aktualiziraneNaKlientskaPoru4ka.rowSelected}" />

			<h:commandButton action="#{aktualiziraneNaDiagnostika.goToAdd()}"
				value="Добави" class="regButton"
				style="width:80px;height:40px;float:right;margin-top:20px;"
				disabled="#{!aktualiziraneNaDiagnostika.goToAddAllowed}" />

			<br />
			<h:outputText value="#{aktualiziraneNaDiagnostika.errorMessage}" />

		</h:form>
	</ui:define>

</ui:composition>
</html>